﻿using UnityEngine;
using System.Collections;

public class Ammo : MonoBehaviour {

	private GameObject player;
	private Transform ownTransform;
	private Camera camara;
	public float speed = 10;
	private float impulse = 1;

	// Use this for initialization
	void Awake () {

		ownTransform = transform;
		camara = GameObject.FindWithTag ("MainCamera").GetComponent ("Camera") as Camera;
	}
	
	// Update is called once per frame
	void FixedUpdate () {

		ownTransform.Translate (Vector3.up * speed * Time.fixedDeltaTime, Space.World);
		if (camara.WorldToViewportPoint (transform.position).y > 1.2*impulse || camara.WorldToViewportPoint (transform.position).y < -0.2*impulse) {
			GameObject.Destroy(gameObject);
		}
	}

	void OnTriggerEnter(Collider collider){

		GameObject.Destroy (collider.gameObject);
		GameObject.Destroy(gameObject);
	}

	public void setLayer(string layer){
		gameObject.layer = LayerMask.NameToLayer (layer);
	}

	public void setOnPlayer(GameObject player, Vector3 offset){
		ownTransform.localPosition = player.transform.position + offset;
	}

	public void setSpeed(float velocidad){
		speed = velocidad;
	}

	public void setImpulse(float tpc){
		impulse = tpc;
	}
}
